﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HNQXYJ.Model;
using HNQXYJ.BLL;
namespace HNQXYJ.HN_City
{
    public partial class UpdateCity : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int id = Convert.ToInt32(Request["id"]);
                HCity city = new CityBLL().GetCityById(id);
                this.txtCityName.Text = city.Name;
                this.txtCityCode.Text = city.SelfCode;
                this.txtLng.Text = city.Lng.ToString();
                this.txtLat.Text = city.Lat.ToString();
            }

        }

        protected void reset_Click(object sender, ImageClickEventArgs e)
        {
            this.txtCityName.Text = "";
            this.txtCityCode.Text = "";
            this.txtLng.Text = "";
            this.txtLat.Text = "";
        }
        //修个城市信息
        protected void add_Click(object sender, ImageClickEventArgs e)
        {
            int id = Convert.ToInt32(Request["id"]);
            HCity city = new HCity();
            city.ID = id;
            city.Name = this.txtCityName.Text.Trim();
            city.SelfCode = this.txtCityCode.Text.Trim();
            city.Lng = Convert.ToDouble(this.txtLng.Text.Trim());
            city.Lat = Convert.ToDouble(this.txtLat.Text.Trim());

            int res = new CityBLL().UpdateCity(city);
            if (res > 0)
            {
                Response.Redirect("CityMgr.aspx");
            }
            else
            {
                this.Label1.Text = "更新数据失败！";
            }

        }
    }
}